import {action, observable, runInAction} from "mobx";
import {BaseResInterface, BaseResInterfaceWithData, sendGetRequest} from "../../../net";
import {defaultArr, excludeEmpty} from "../../../util";
import {ProductModelInterface} from "../../../net/instance/CommenModelInstance";


interface Search {

}

export class SearchStore {
    @observable products: ProductModelInterface[] = defaultArr;

    @action.bound
    async getProductsByName(name: string) {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<ProductModelInterface[]>>("main/getProductsByName", {
            name
        });
        runInAction(() => {
            this.products = data;
        });
    }

}

const SearchStoreInstance = new SearchStore();
export default SearchStoreInstance